import {createSlice} from '@reduxjs/toolkit';

//定义一个接口
interface CountType{
  value: number;
}

//声明状态的初始值
let initialState: CountType = {
  value: 100
}

//创建 slice
let slice = createSlice({
  name: 'count',
  initialState: initialState,
  reducers: {
    add: (state, action) => {
      state.value += 1
    },
    sub: (state, action) => {
      state.value -= 1
    }
  }
});

//获取 reducer 函数
let reducer = slice.reducer;

//获取 action creator
export let {add, sub} = slice.actions;

//暴露 reducer
export default reducer;